#include "linked_list.h"
#include <stdlib.h>
#include <stdio.h>
int mainLL() {
    int a = 5;
    int b = 7;
    int c = 2;
    llist *list = create_list();
    enqueue(list, &c);
    enqueue(list, &b);
    enqueue(list, &a);
    int *ret;
    while(ret = (int *)dequeue(list))
          printf("%d\n", *ret);
    
    enqueue(list, &c);
    enqueue(list, &b);
    
    while(ret = (int *)dequeue(list))
        printf("%d\n", *ret);
    return 0;
}

llist *create_list() {
    llist *list = 0;
    if(list = (llist *)malloc(sizeof(llist))) {
        list -> head = 0;
        list -> tail = 0;
        list -> size = 0;
    }
    return list;
    
}

void enqueue(llist *list, void *data) {
    node *new = malloc(sizeof(node));
    new -> data = data;
    new -> next = 0;
    if(list -> size)
        list -> tail -> next = new;
    else {
        list -> head = new;
    }
    list -> tail = new; 
    list -> size++;
}

void *dequeue(llist *list) {
    void *ret = 0;
    node *temp = list -> head;
    if(list -> size) {
        ret = list -> head -> data;
        list -> head = list -> head -> next;
        list -> size--;
        free(temp);
        if(list -> size == 0) {
            list -> head = 0;
            list -> tail = 0;
        }
    }
    return ret;
}

